<template>
  <el-dialog
    title="课程列表"
    :visible.sync="dialogVisible"
    width="1000px"
    :close-on-click-modal="false"
  >
    <div class="wrap">
      <el-table :data="tableData" style="width: 100%" v-loading="loading">
        <el-table-column prop="title" label="主题" width="180">
        </el-table-column>
        <el-table-column prop="teacher" label="主讲老师" width="180">
        </el-table-column>
        <el-table-column prop="address" label="所属课程">
          <template slot-scope="{ row }">
            <span>{{ row.sysCourse ? row.sysCourse.title : '暂无数据' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="{ row }">
            <span v-show="row.status == 0">暂存</span>
            <span v-show="row.status == 1">显示</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150" fixed="right">
          <template slot-scope="{ row }">
            <el-button-group>
              <!-- <el-button
                type="primary"
                size="mini"
                @click="handleStudentList(row)"
                >查看</el-button
              > -->

              <el-button type="danger" size="mini" @click="handleDelete(row)"
                >删除</el-button
              >
            </el-button-group>
          </template>
        </el-table-column>
        <div slot="empty" class="emptyBg">
          <el-empty :image-size="200"></el-empty>
        </div>
      </el-table>
      <Pagination
        v-show="parseInt(pageObj.count) > 0"
        :total="parseInt(pageObj.count)"
        @change="getList"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
      />
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">关 闭</el-button>
    </span>
  </el-dialog>
</template>
<script>
import {
  eduTeachingCourseQuery,
  eduTeachingCourseDelete,
} from '@/api/admin/teach/eduTeachingCourse.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      dialogVisible: false,
      loading: false,
      listQuery: {
        page: 1,
        limit: 10,
        eduTeachingId: undefined,
      },
      tableData: [],
      pageObj: {},
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) return
      Bus.$emit('refreshClassroomList')
    },
  },
  mounted() {
    Bus.$on('changeCourse', (id) => {
      this.listQuery.eduTeachingId = id
      this.tableData = []
      this.pageObj = {}
      this.getList()
      this.dialogVisible = true
    })
  },
  beforeDestroy() {
    Bus.$off('changeCourse')
  },
  methods: {
    async getList() {
      this.loading = true
      let res = await eduTeachingCourseQuery(this.listQuery)
      this.tableData = res.data.data
      this.pageObj = res.data
      this.loading = false
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      eduTeachingCourseDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>
<style scoped lang="scss">
.wrap {
  min-height: 500px;
}
</style>